﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kooboo.Domain;
using System.ComponentModel.Composition;

namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(IEntityDeleteCommand<ICartItem>))]
    public class CartItemDeleteCommand : EntityDeleteCommand<ICartItem>, IEntityDeleteCommand<ICartItem>
    {
        protected override string TableName
        {
            get { return "CartItem"; }
        }

        protected override string BuildCondition()
        {
            var ids = this.EntitySet.Select(i => i.Id).ToArray();
            var where = string.Empty;
            if (ids.Length == 0)
            {
                where = " 1=2 ";
            }
            else
            {
                where = " Id in (" + string.Join(", ", ids) + ") ";
            }

            return where;
        }


        IQueryable<ICartItem> IEntityDeleteCommand<ICartItem>.EntitySet
        {
            get
            {
                return this.EntitySet.OfType<ICartItem>();
            }
            set
            {
                this.EntitySet = value.OfType<ICartItem>();
            }
        }
    }
}
